package com.itboye.lottery.utils;

import com.itboye.lottery.bean.CodeBean;
import com.itboye.lottery.bean.ZqBetListItem;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Combination {
    //elements为要操作的数据集合，即长度为M的容器，num为每次取的元素个数
    public static List<List<CodeBean>> combiner(List<CodeBean> elements, int num,
                                                List<List<CodeBean>> result) {
        //当num为1时，即返回结果集
        if (num == 1) {
            return result;
        }
        //result的长度是变化的，故把原始值赋给变量leng
        int leng = result.size();
        //循环遍历，将 elements每两个元素放到一起，作为result中的一个元素
        for (int i = 0; i < leng; i++) {
            for (int j = 0; j < elements.size(); j++) {
                if (!result.get(i).contains(elements.get(j))) {
                    List<CodeBean> list1 = new ArrayList<>();
                    for (int j2 = 0; j2 < result.get(i).size(); j2++) {
                        list1.add(result.get(i).get(j2));
                    }
                    list1.add(elements.get(j));
                    Collections.sort(list1);
                    result.add(list1);
                }
            }
        }
        //将result中的循环遍历前的数据删除
        for (int i = 0; i < leng; i++) {
            result.remove(0);
        }
        //对result进行去重
        Iterator<List<CodeBean>> it = result.iterator();
        List<List<CodeBean>> listTemp = new ArrayList<>();
        while (it.hasNext()) {
            List<CodeBean> a = it.next();
            if (listTemp.contains(a)) {
                it.remove();
            } else {
                listTemp.add(a);
            }
        }
        //递归计算，根据num的值来确定递归次数
        combiner(elements, num-1, result);
        return result;
    }

//    //elements为要操作的数据集合，即长度为M的容器，num为每次取的元素个数
//    public static List<List<CodeBean>> findsort(List<CodeBean> elements, int num) {
//        if (elements == null) {
//            return new ArrayList<>();
//        }
//        if (num > elements.size()) {
//            return new ArrayList<>();
//        }
//
//        List<List<CodeBean>> result = new ArrayList<>();
//        //将elements中的数据取出来，存到新的list中，为后续计算做准备
//        for (int i = 0; i < elements.size(); i++) {
//            List<CodeBean> list = new ArrayList<>();
//            list.add(elements.get(i));
//            result.add(list);
//        }
//        return combiner(elements, num, result);
//    }

    /**
     * 从n个数字中选择m个数字
     * @param a
     * @param m
     * @return
     */
    public static List combine(int[] a,int m){
        int n = a.length;
        List result = new ArrayList();
        if(m>n){
            return result;
        }

        if(m==n){
            result.add(1);
            return result;
        }
        int[] bs = new int[n];
        for(int i=0;i<n;i++){
            bs[i]=0;
        }
        //初始化
        for(int i=0;i<m;i++){
            bs[i]=1;
        }
        boolean flag = true;
        boolean tempFlag = false;
        int pos = 0;
        int sum = 0;
        //首先找到第一个10组合，然后变成01，同时将左边所有的1移动到数组的最左边
        do{
            sum = 0;
            pos = 0;
            tempFlag = true;
            result.add(print(bs,a,m));

            for(int i=0;i<n-1;i++){
                if(bs[i]==1 && bs[i+1]==0 ){
                    bs[i]=0;
                    bs[i+1]=1;
                    pos = i;
                    break;
                }
            }
            //将左边的1全部移动到数组的最左边

            for(int i=0;i<pos;i++){
                if(bs[i]==1){
                    sum++;
                }
            }
            for(int i=0;i<pos;i++){
                if(i<sum){
                    bs[i]=1;
                }else{
                    bs[i]=0;
                }
            }

            //检查是否所有的1都移动到了最右边
            for(int i= n-m;i<n;i++){
                if(bs[i]==0){
                    tempFlag = false;
                    break;
                }
            }
            flag = !tempFlag;

        }while(flag);
        result.add(print(bs,a,m));

        return result;
    }

    private static int[] print(int[] bs,int[] a,int m){
        int[] result = new int[m];
        int pos= 0;
        for(int i=0;i<bs.length;i++){
            if(bs[i]==1){
                result[pos]=a[i];
                pos++;
            }
        }
        return result ;
    }

    //elements为要操作的数据集合，即长度为M的容器，num为每次取的元素个数
    public static int findsort(List<CodeBean> elements, int num) {
        //形如C(9,5)=(9X8X7X6X5)÷(1X2X3X4X5)
        if (elements == null) {
            return 0;
        }
        if (num > elements.size()) {
            return 0;
        }
        int code[]=new int[elements.size()];
        for (int i = 1; i < elements.size(); i++) {
            code[i]=elements.get(i).getCodeValue();
        }
        return combine(code,num).size();
    }

    /**
     * 计算足球注数
     *
     * @param zqBetListItemArrayList
     * @param buyType
     * @return
     */
    public static int getVoteNums(ArrayList<ZqBetListItem> zqBetListItemArrayList, String buyType) {
        if (zqBetListItemArrayList == null) {
            return 0;
        }
        int zs = 0;
        List<Integer> sa = new ArrayList<Integer>();
        List<Integer> sb = new ArrayList<Integer>();
        int matchNum = zqBetListItemArrayList.size();
        for (int i = 0; i < matchNum; i++) {
            int length = 0;
            length += zqBetListItemArrayList.get(i).getSpfList().size();
            length += zqBetListItemArrayList.get(i).getRspfList().size();
            length += zqBetListItemArrayList.get(i).getBfList().size();
            length += zqBetListItemArrayList.get(i).getBqcList().size();
            length += zqBetListItemArrayList.get(i).getZjqList().size();


            length += zqBetListItemArrayList.get(i).getRfsfList().size();
            length += zqBetListItemArrayList.get(i).getFrsfList().size();
            length += zqBetListItemArrayList.get(i).getDxfList().size();
            length += zqBetListItemArrayList.get(i).getSfcList().size();
//            sb.add(length);
            sa.add(length);
        }
        int[] sas = new int[sa.size()];
        for (int i = 0; i < sa.size(); i++) {
            sas[i] = (int) sa.get(i);
        }

        int[] sbs = new int[sb.size()];
        for (int i = 0; i < sb.size(); i++) {
            sbs[i] = (int) sb.get(i);
        }
        /* int minabs = sa.size();*/

        int minabs = sb.size();
        int maxabs = sb.size();

        String[] buyType_arr = buyType.split(",");

        for (int j = 0; j < buyType_arr.length; j++) {
            zs += myCalc(buyType_arr[j], "Combin", sas, sbs, minabs, maxabs);

        }
        return zs;
    }

    private static int myCalc(String passType, String wagerType, int[] sa, int[] sb, int minabs, int maxabs) {
        if (sb.length == 0) {
            return calc(passType, wagerType, sa, sb);
        } else {
            int wcount = 0;
            for (int k = minabs; k <= maxabs; k++) {
                List<int[]> bm = combinArray(sb, k);
                for (int j = 0; j < bm.size(); j++) {
                    //System.out.println("返回的值:"+bm.get(j));
                    //wcount += calc(passType, wagerType, sa, bm.get(j));
                    int[] ttmp = bm.get(j);
                    wcount += calc(passType, wagerType, sa, ttmp);
                }
            }
            return wcount;
        }
    }

    private static int calc(String passType, String wagerType, int[] sa, int[] sb) {
        int WagerCount = 0;
        String[] t_list = passType.split("\\*");
        int pc = Integer.parseInt(t_list[0]);

        if ("Combin".equals(wagerType)) {
            int AbsCount = sb.length;
            int len = pc - AbsCount;
            if (len == 0 && AbsCount > 0) {
                int[] pm = new int[pc];
                for (int P = 0; P < sb.length; P++) {
                    int AbsVoteC = sb[P];
                    for (int k = 0; k < pc; k++) {
                        if (pm[k] == 0) {
                            pm[k] = AbsVoteC;
                            break;
                        }
                    }
                }

                String pstr = "";
                for (int i = 0; i < pc; i++) {
                    pstr += pm[i] + ",";
                }
                pstr = pstr.substring(0, pstr.length() - 1);
                WagerCount += calcuteWC(passType, pstr);
            } else {
                int[] arr = new int[sa.length];
                for (int i = 0; i < sa.length; i++) {
                    arr[i] = i;
                }

                if (len <= 0) {
                    return 0;
                }
                List<int[]> w = combinArray(arr, len);
                //System.out.println("w:"+w.size());

            /*    for (int i = 0; i < w.size(); i++) {
                    int[] splitArr = w.get(i);
                    int[] pm = new int[pc];
                    for (int k = 0; k < pc; k++) {
                        if (k > splitArr.length - 1) break;
                        int d = splitArr[k];
                        pm[k] = parseFloat(sa[d] + "");
                    }

                    if (AbsCount > 0) {*/

                for (int i = 0; i < w.size(); i++) {
                    int[] splitArr = w.get(i);
                    System.out.println("ww:" + w.get(i));


                    int[] ttmp = w.get(i);
                    for (int y = 0; y < ttmp.length; y++) {
                        System.out.println("ww返回的值" + ttmp[y]);
                    }


                    int[] pm = new int[pc];
                    for (int k = 0; k < ttmp.length; k++) {
                        System.out.println("KK:" + k);
                        int d = splitArr[k];
                        pm[k] = parseFloat(sa[d] + "");
                    }

                    if (AbsCount > 0) {
                        for (int p = 0; p < sb.length; p++) {
                            int AbsVoteC = sb[p];
                            for (int k = 0; k < pc; k++) {

								/*
                                try {
							        Pattern rp = Pattern.compile("^\\d+");
							        Matcher m = rp.matcher(String.valueOf(pm[k]));
							        if (!m.find()) {
							        	pm[k] = AbsVoteC;
										break;
							        }
							    } catch (NumberFormatException e) {
							        e.printStackTrace();
							    }
							    */


                                if (pm[k] == 0 || "null".equals(String.valueOf(pm[k]))) {
                                    pm[k] = AbsVoteC;
                                    break;
                                }
                            }
                        }
                    }

                    String pstr = "";
                    for (int n = 0; n < pc; n++) {
                        pstr += pm[n] + ",";
                    }
                    pstr = pstr.substring(0, pstr.length() - 1);
                    //System.out.println("pstr:"+pstr);
                    WagerCount += calcuteWC(passType, pstr);
                }
            }
        } else if ("Subsection".equals(wagerType)) {
            // //to do
            WagerCount += 0;
        }

        return WagerCount;
    }

    //从长度为n的数组中随机的选择m个整数


    private static List<int[]> combinArray(int[] a, int m) {
        Arrays.sort(a);
        List<int[]> list = new ArrayList<int[]>();
        int n = a.length;
        if (n <= m) {
            list.add(a);// 添加下一种默认组合
        } else {
            boolean end = false; // 是否是最后一种组合的标记
            // 生成辅助数组。首先初始化，将数组前n个元素置1，表示第一个组合为前n个数。
            int[] tempNum = new int[n];
            for (int i = 0; i < n; i++) {
                if (i < m) {
                    tempNum[i] = 1;
                } else {
                    tempNum[i] = 0;
                }
            }
            list.add(createResult(a, tempNum, m));// 打印第一种默认组合
            int k = 0;//标记位
            while (!end) {
                boolean findFirst = false;
                boolean swap = false;
                // 然后从左到右扫描数组元素值的"10"组合，找到第一个"10"组合后将其变为"01"
                for (int i = 0; i < n; i++) {
                    int l = 0;
                    if (!findFirst && tempNum[i] == 1) {
                        k = i;
                        findFirst = true;
                    }
                    if (tempNum[i] == 1 && tempNum[i + 1] == 0) {
                        tempNum[i] = 0;
                        tempNum[i + 1] = 1;
                        swap = true;
                        for (l = 0; l < i - k; l++) { // 同时将其左边的所有"1"全部移动到数组的最左端。
                            tempNum[l] = tempNum[k + l];
                        }
                        for (l = i - k; l < i; l++) {
                            tempNum[l] = 0;
                        }
                        if (k == i && i + 1 == n - m) {//假如第一个"1"刚刚移动到第n-m+1个位置,则终止整个寻找
                            end = true;
                        }
                    }
                    if (swap) {
                        break;
                    }
                }

                list.add(createResult(a, tempNum, m));// 添加下一种默认组合
            }

        }
        return list;
    }


    // 根据辅助数组和原始数组生成结果数组
    public static int[] createResult(int[] a, int[] temp, int m) {
        int[] result = new int[m];
        int j = 0;
        for (int i = 0; i < a.length; i++) {
            if (temp[i] == 1) {
                result[j] = a[i];
                // System.out.println("result[" + j + "]:" + result[j]);
                j++;
            }
        }
        return result;
    }

    public static int calcuteWC(String passtype, String str) {
        String[] arr = str.split(",");
        int re = 0,
                a = parseFloat(arr[0]),
                b = (arr.length > 1) ? parseFloat(arr[1]) : 0,
                c = (arr.length > 2) ? parseFloat(arr[2]) : 0,
                d = (arr.length > 3) ? parseFloat(arr[3]) : 0,
                e = (arr.length > 4) ? parseFloat(arr[4]) : 0,
                f = (arr.length > 5) ? parseFloat(arr[5]) : 0,
                g = (arr.length > 6) ? parseFloat(arr[6]) : 0,
                h = (arr.length > 7) ? parseFloat(arr[7]) : 0,
                i = (arr.length > 8) ? parseFloat(arr[8]) : 0,
                j = (arr.length > 9) ? parseFloat(arr[9]) : 0,
                k = (arr.length > 10) ? parseFloat(arr[10]) : 0,
                l = (arr.length > 11) ? parseFloat(arr[11]) : 0,
                m = (arr.length > 12) ? parseFloat(arr[12]) : 0,
                n = (arr.length > 13) ? parseFloat(arr[13]) : 0,
                o = (arr.length > 14) ? parseFloat(arr[14]) : 0;

        if (passtype.equals("1*1")) {
            re = a;

        } else if (passtype.equals("2*1")) {
            re = a * b;

        } else if (passtype.equals("2*3")) {
            re = (a + 1) * (b + 1) - 1;

        } else if (passtype.equals("3*1")) {
            re = a * b * c;

        } else if (passtype.equals("3*3")) {
            re = a * b + a * c + b * c;

        } else if (passtype.equals("3*4")) {
            re = a * b * c + a * b + a * c + b * c;

        } else if (passtype.equals("3*7")) {
            re = (a + 1) * (b + 1) * (c + 1) - 1;

        } else if (passtype.equals("4*1")) {
            re = a * b * c * d;

        } else if (passtype.equals("4*4")) {
            re = a * b * c + a * b * d + a * c * d + b * c * d;

        } else if (passtype.equals("4*5")) {
            re = (a + 1) * (b + 1) * (c + 1) * (d + 1) - (a * (b + c + d + 1) + b * (c + d + 1) + (c + 1) * (d + 1));

        } else if (passtype.equals("4*6")) {
            re = a * b + a * c + a * d + b * c + b * d + c * d;

        } else if (passtype.equals("4*11")) {
            re = (a + 1) * (b + 1) * (c + 1) * (d + 1) - (a + b + c + d + 1);

        } else if (passtype.equals("4*15")) {
            re = (a + 1) * (b + 1) * (c + 1) * (d + 1) - 1;

        } else if (passtype.equals("5*1")) {
            re = a * b * c * d * e;

        } else if (passtype.equals("5*5")) {
            re = a * b * c * d + a * b * c * e + a * b * d * e + a * c * d * e + b * c * d * e;

        } else if (passtype.equals("5*6")) {
            re = a * b * c * d * e + a * b * c * d + a * b * c * e + a * b * d * e + a * c * d * e + b * c * d * e;

        } else if (passtype.equals("5*10")) {
            re = a * b + a * c + a * d + a * e + b * c + b * d + b * e + c * d + c * e + d * e;

        } else if (passtype.equals("5*16")) {
            re = (a + 1) * (b + 1) * (c + 1) * (d + 1) * (e + 1) - (a * (b + c + d + e + 1) + b * (c + d + e + 1) + c * (d + e + 1) + (d + 1) * (e + 1));

        } else if (passtype.equals("5*20")) {
            re = a * b * c + a * b * d + a * b * e + a * c * d + a * c * e + a * d * e + b * c * d + b * c * e + b * d * e + c * d * e + a * b + a * c + a * d + a * e + b * c + b * d + b * e + c * d + c * e + d * e;

        } else if (passtype.equals("5*26")) {
            re = (a + 1) * (b + 1) * (c + 1) * (d + 1) * (e + 1) - (a + b + c + d + e + 1);

        } else if (passtype.equals("5*31")) {
            re = (a + 1) * (b + 1) * (c + 1) * (d + 1) * (e + 1) - 1;

        } else if (passtype.equals("6*1")) {
            re = a * b * c * d * e * f;

        } else if (passtype.equals("6*6")) {
            re = a * b * c * d * e + a * b * c * d * f + a * b * c * e * f + a * b * d * e * f + a * c * d * e * f + b * c * d * e * f;

        } else if (passtype.equals("6*7")) {
            re = a * b * c * d * e * f + a * b * c * d * e + a * b * c * d * f + a * b * c * e * f + a * b * d * e * f + a * c * d * e * f + b * c * d * e * f;

        } else if (passtype.equals("6*15")) {
            re = a * b + a * c + a * d + a * e + a * f + b * c + b * d + b * e + b * f + c * d + c * e + c * f + d * e + d * f + e * f;

        } else if (passtype.equals("6*20")) {
            re = a * b * c + a * b * d + a * b * e + a * b * f + a * c * d + a * c * e + a * c * f + a * d * e + a * d * f + a * e * f + b * c * d + b * c * e + b * c * f + b * d * e + b * d * f + b * e * f + c * d * e + c * d * f + c * e * f + d * e * f;

        } else if (passtype.equals("6*22")) {
            re = a * b * c * d * e * f + a * b * c * d * e + a * b * c * d * f + a * b * c * e * f + a * b * d * e * f + a * c * d * e * f + b * c * d * e * f + a * b * c * d + a * b * c * e + a * b * c * f + a * b * d * e + a * b * d * f + a * b * e * f + a * c * d * e + a * c * d * f + a * c * e * f + a * d * e * f + b * c * d * e + b * c * d * f + b * c * e * f + b * d * e * f + c * d * e * f;

        } else if (passtype.equals("6*35")) {
            re = a * b * c + a * b * d + a * b * e + a * b * f + a * c * d + a * c * e + a * c * f + a * d * e + a * d * f + a * e * f + b * c * d + b * c * e + b * c * f + b * d * e + b * d * f + b * e * f + c * d * e + c * d * f + c * e * f + d * e * f + a * b + a * c + a * d + a * e + a * f + b * c + b * d + b * e + b * f + c * d + c * e + c * f + d * e + d * f + e * f;

        } else if (passtype.equals("6*42")) {
            re = (a + 1) * (b + 1) * (c + 1) * (d + 1) * (e + 1) * (f + 1) - (a * (b + c + d + e + f + 1) + b * (c + d + e + f + 1) + c * (d + e + f + 1) + d * (e + f + 1) + (e + 1) * (f + 1));

        } else if (passtype.equals("6*50")) {
            re = (a + 1) * (b + 1) * (c + 1) * (d + 1) * (e + 1) * (f + 1) - (a + b + c + d + e + f + 1) - (a * b * c * d * e + a * b * c * d * f + a * b * c * e * f + a * b * d * e * f + a * c * d * e * f + b * c * d * e * f + a * b * c * d * e * f);

        } else if (passtype.equals("6*57")) {
            re = (a + 1) * (b + 1) * (c + 1) * (d + 1) * (e + 1) * (f + 1) - (a + b + c + d + e + f + 1);

        } else if (passtype.equals("6*63")) {
            re = (a + 1) * (b + 1) * (c + 1) * (d + 1) * (e + 1) * (f + 1) - 1;

        } else if (passtype.equals("7*1")) {
            re = a * b * c * d * e * f * g;

        } else if (passtype.equals("7*7")) {
            re = a * b * c * d * e * f + a * b * c * d * e * g + a * b * c * d * f * g + a * b * c * e * f * g + a * b * d * e * f * g + a * c * d * e * f * g + b * c * d * e * f * g;

        } else if (passtype.equals("7*8")) {
            re = a * b * c * d * e * f * g + a * b * c * d * e * f + a * b * c * d * e * g + a * b * c * d * f * g + a * b * c * e * f * g + a * b * d * e * f * g + a * c * d * e * f * g + b * c * d * e * f * g;

        } else if (passtype.equals("7*21")) {
            re = a * b * c * d * e + a * b * c * d * f + a * b * c * d * g + a * b * c * e * f + a * b * c * e * g + a * b * c * f * g + a * b * d * e * f + a * b * d * e * g + a * b * d * f * g + a * b * e * f * g + a * c * d * e * f + a * c * d * e * g + a * c * d * f * g + a * c * e * f * g + a * d * e * f * g + b * c * d * e * f + b * c * d * e * g + b * c * d * f * g + b * c * e * f * g + b * d * e * f * g + c * d * e * f * g;

        } else if (passtype.equals("7*35")) {
            re = a * b * c * d + a * b * c * e + a * b * c * f + a * b * c * g + a * b * d * e + a * b * d * f + a * b * d * g + a * b * e * f + a * b * e * g + a * b * f * g + a * c * d * e + a * c * d * f + a * c * d * g + a * c * e * f + a * c * e * g + a * c * f * g + a * d * e * f + a * d * e * g + a * d * f * g + a * e * f * g + b * c * d * e + b * c * d * f + b * c * d * g + b * c * e * f + b * c * e * g + b * c * f * g + b * d * e * f + b * d * e * g + b * d * f * g + b * e * f * g + c * d * e * f + c * d * e * g + c * d * f * g + c * e * f * g + d * e * f * g;

        } else if (passtype.equals("7*120")) {
            re = (a + 1) * (b + 1) * (c + 1) * (d + 1) * (e + 1) * (f + 1) * (g + 1) - (a + b + c + d + e + f + g + 1);

        } else if (passtype.equals("8*1")) {
            re = a * b * c * d * e * f * g * h;

        } else if (passtype.equals("8*8")) {
            re = a * b * c * d * e * f * g + a * b * c * d * e * f * h + a * b * c * d * e * g * h + a * b * c * d * f * g * h + a * b * c * e * f * g * h + a * b * d * e * f * g * h + a * c * d * e * f * g * h + b * c * d * e * f * g * h;

        } else if (passtype.equals("8*9")) {
            re = a * b * c * d * e * f * g * h + a * b * c * d * e * f * g + a * b * c * d * e * f * h + a * b * c * d * e * g * h + a * b * c * d * f * g * h + a * b * c * e * f * g * h + a * b * d * e * f * g * h + a * c * d * e * f * g * h + b * c * d * e * f * g * h;

        } else if (passtype.equals("8*28")) {
            re = a * b * c * d * e * f + a * b * c * d * e * g + a * b * c * d * e * h + a * b * c * d * f * g + a * b * c * d * f * h + a * b * c * d * g * h + a * b * c * e * f * g + a * b * c * e * f * h + a * b * c * e * g * h + a * b * c * f * g * h + a * b * d * e * f * g + a * b * d * e * f * h + a * b * d * e * g * h + a * b * d * f * g * h + a * b * e * f * g * h + a * c * d * e * f * g + a * c * d * e * f * h + a * c * d * e * g * h + a * c * d * f * g * h + a * c * e * f * g * h + a * d * e * f * g * h + b * c * d * e * f * g + b * c * d * e * f * h + b * c * d * e * g * h + b * c * d * f * g * h + b * c * e * f * g * h + b * d * e * f * g * h + c * d * e * f * g * h;

        } else if (passtype.equals("8*56")) {
            re = a * b * c * d * e + a * b * c * d * f + a * b * c * d * g + a * b * c * d * h + a * b * c * e * f + a * b * c * e * g + a * b * c * e * h + a * b * c * f * g + a * b * c * f * h + a * b * c * g * h + a * b * d * e * f + a * b * d * e * g + a * b * d * e * h + a * b * d * f * g + a * b * d * f * h + a * b * d * g * h + a * b * e * f * g + a * b * e * f * h + a * b * e * g * h + a * b * f * g * h + a * c * d * e * f + a * c * d * e * g + a * c * d * e * h + a * c * d * f * g + a * c * d * f * h + a * c * d * g * h + a * c * e * f * g + a * c * e * f * h + a * c * e * g * h + a * c * f * g * h + a * d * e * f * g + a * d * e * f * h + a * d * e * g * h + a * d * f * g * h + a * e * f * g * h + b * c * d * e * f + b * c * d * e * g + b * c * d * e * h + b * c * d * f * g + b * c * d * f * h + b * c * d * g * h + b * c * e * f * g + b * c * e * f * h + b * c * e * g * h + b * c * f * g * h + b * d * e * f * g + b * d * e * f * h + b * d * e * g * h + b * d * f * g * h + b * e * f * g * h + c * d * e * f * g + c * d * e * f * h + c * d * e * g * h + c * d * f * g * h + c * e * f * g * h + d * e * f * g * h;

        } else if (passtype.equals("8*70")) {
            re = a * b * c * d + a * b * c * e + a * b * c * f + a * b * c * g + a * b * c * h + a * b * d * e + a * b * d * f + a * b * d * g + a * b * d * h + a * b * e * f + a * b * e * g + a * b * e * h + a * b * f * g + a * b * f * h + a * b * g * h + a * c * d * e + a * c * d * f + a * c * d * g + a * c * d * h + a * c * e * f + a * c * e * g + a * c * e * h + a * c * f * g + a * c * f * h + a * c * g * h + a * d * e * f + a * d * e * g + a * d * e * h + a * d * f * g + a * d * f * h + a * d * g * h + a * e * f * g + a * e * f * h + a * e * g * h + a * f * g * h + b * c * d * e + b * c * d * f + b * c * d * g + b * c * d * h + b * c * e * f + b * c * e * g + b * c * e * h + b * c * f * g + b * c * f * h + b * c * g * h + b * d * e * f + b * d * e * g + b * d * e * h + b * d * f * g + b * d * f * h + b * d * g * h + b * e * f * g + b * e * f * h + b * e * g * h + b * f * g * h + c * d * e * f + c * d * e * g + c * d * e * h + c * d * f * g + c * d * f * h + c * d * g * h + c * e * f * g + c * e * f * h + c * e * g * h + c * f * g * h + d * e * f * g + d * e * f * h + d * e * g * h + d * f * g * h + e * f * g * h;

        } else if (passtype.equals("8*247")) {
            re = (a + 1) * (b + 1) * (c + 1) * (d + 1) * (e + 1) * (f + 1) * (g + 1) * (h + 1) - (a + b + c + d + e + f + g + h + 1);

        } else if (passtype.equals("9*1")) {
            re = a * b * c * d * e * f * g * h * i;

        } else if (passtype.equals("10*1")) {
            re = a * b * c * d * e * f * g * h * i * j;

        } else if (passtype.equals("11*1")) {
            re = a * b * c * d * e * f * g * h * i * j * k;

        } else if (passtype.equals("12*1")) {
            re = a * b * c * d * e * f * g * h * i * j * k * l;

        } else if (passtype.equals("13*1")) {
            re = a * b * c * d * e * f * g * h * i * j * k * l * m;

        } else if (passtype.equals("14*1")) {
            re = a * b * c * d * e * f * g * h * i * j * k * l * m * n;

        } else if (passtype.equals("15*1")) {
            re = a * b * c * d * e * f * g * h * i * j * k * l * m * n * o;
        }
        return re;
    }

    private static int parseFloat(String str) {
        int i = 0;
        try {
            Pattern p = Pattern.compile("^\\d+");
            Matcher m = p.matcher(str);
            if (m.find()) {
                i = Integer.valueOf(m.group());
            } else {
                i = 0;
            }
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
        return i;
    }
}
